﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Controller
    {
        public static void create()
        {
            using (var context = new Context())
            {
                context.Database.CreateIfNotExists();//如果数据库不存在时则创建
            }

            Console.Write("DB has Created!");//提示DB创建成功
            Console.Read();
        }

        public static void update()
        {
            #region 3.0 更新记录
            //using (var context = new Context())
            //{
            //    var donators = context.Donators;
            //    if (donators.Any())
            //    {
            //        var toBeUpdatedDonator = donators.First(d => d.Name == "醉千秋");
            //        toBeUpdatedDonator.Name = "醉、千秋";
            //        context.SaveChanges();
            //    }
            //}

            #endregion
        }
        public static void Retrieve()
        {
            //using (var context = new Context())
            //{
            //    var donators = context.Donators;
            //    Console.WriteLine("Id\t\t姓名\t\t金额\t\t赞助日期");
            //    foreach (var donator in donators)
            //    {
            //        Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}", donator.DonatorId, donator.Name, donator.Amount, donator.DonateDate.ToShortDateString());
            //    }
            //}
            Console.Read();

        }

        public static void delete()
        {
            #region 4.0 删除记录
            //using (var context = new Context())
            //{
            //    var toBeDeletedDonator = context.Donators.Single(d => d.Name == "待打赏");//根据Name找到要删除的测试数据
            //    if (toBeDeletedDonator != null)
            //    {
            //        context.Donators.Remove(toBeDeletedDonator);//如果满足条件，就将该对象使用Remove方法标记为Deleted
            //        context.SaveChanges();//最后持久化到数据库
            //    }
            //}
            #endregion
        }

        public static void addPayway()
        {
            //using (var context = new Context())
            //{
            //    context.PayWays.AddRange(new List<PayWay>
            //        {
            //            new PayWay{Name = "支付宝"},
            //            new PayWay{Name = "微信"},
            //            new PayWay{Name = "QQ红包"}
            //        });

            //    context.SaveChanges();
            //}

        }

        public static void add()
        {
            //using (var context = new Context())
            //{
            //    context.Database.CreateIfNotExists();//如果数据库不存在时则创建
            //    var donators = new List<Donator>
            //    {
            //        new Donator
            //        {
            //          Name   = "陈志康",
            //          Amount = 50,
            //          DonateDate = new DateTime(2016, 4, 7)
            //        },
            //        new Donator
            //        {
            //            Name = "海风",
            //            Amount = 5,
            //            DonateDate = new DateTime(2016, 4, 8)
            //        },
            //        new Donator
            //        {
            //            Name = "醉千秋",
            //            Amount = 18.8m,
            //            DonateDate = new DateTime(2016, 4, 15)
            //        }
            //    };

            //    context.Donators.AddRange(donators);
            //    context.SaveChanges();
            //}
            //// Console.Write("DB has Created!");//提示DB创建成功
            //Console.Write("Creation Finished!");//提示创建完成
            //Console.Read();
        }


    }
}
